package com.ruoyi.web.controller.system;

import com.ruoyi.com.domain.ComDepartment;
import com.ruoyi.com.service.IComDepartmentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ComUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公共部门Controller
 *
 * @author sunye
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/system/comDepartment")
@Api(value = "部门管理", tags = {"部门管理"})
public class SysDepartmentController extends BaseController
{
    @Autowired
    private IComDepartmentService comDepartmentService;

    /**
     * 查询部门列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询部门列表")
    public AjaxResult list(ComDepartment comDepartment)
    {
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        comDepartment.setDeptId(deptId);
        List<ComDepartment> list = comDepartmentService.selectComDepartmentList(comDepartment);
        return success(list);
    }



    /**
     * 查询部门和角色的关系
     */
    @ApiOperation(value = "统一门户查询部门和角色的关系")
    @GetMapping("selectDepartmentRole/{departmentId}")
    public AjaxResult selectDepartmentRole(@PathVariable("departmentId") Long departmentId)
    {
        return success(comDepartmentService.selectDepartmentRole(departmentId));
    }

    /**
     * 绑定部门和角色的关系
     */
    @Log(title = "绑定部门和角色的关系", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "绑定部门和角色的关系")
    @PostMapping("bindDepartmentRole")
    public AjaxResult bindDepartmentRole(@RequestBody ComDepartment comDepartment)
    {
        return toAjax(comDepartmentService.bindDepartmentRole(comDepartment));
    }
}
